package com.flyxiaozhu.erp.core.stockrules;

import com.flyxiaozhu.erp.core.entities.Goods;
import com.flyxiaozhu.erp.core.entities.GoodsOrder;
import com.flyxiaozhu.erp.core.entities.GoodsOrderDetail;
import com.flyxiaozhu.erp.core.entities.GoodsSku;
import com.flyxiaozhu.erp.core.libs.AppException;
import com.flyxiaozhu.erp.core.libs.JSONResult;

import javax.servlet.http.HttpServletRequest;

public interface IStockRule {
    int id(); // 规则id

    String name(); // 类型名称

    int type(); // 订单类型

    /**
     * 预检查
     *
     * @param goods
     * @param nullableSku
     * @param num
     * @param request
     * @return
     */
    JSONResult check(Goods goods, GoodsSku nullableSku, int num, HttpServletRequest request);

    /**
     * 锁定库存，相当于想在数据库中消化库存
     *
     * @param order
     * @param detail
     * @param goods
     * @param nullableSku
     * @param request
     * @return
     * @throws AppException
     */
    JSONResult lockStock(GoodsOrder order, GoodsOrderDetail detail, Goods goods, GoodsSku nullableSku, HttpServletRequest request) throws AppException;

    /**
     * 发货
     *
     * @param order
     * @param detail
     * @param goods
     * @param nullableSku
     * @param request
     * @return
     * @throws AppException
     */
    JSONResult delivery(GoodsOrder order, GoodsOrderDetail detail, Goods goods, GoodsSku nullableSku, HttpServletRequest request) throws AppException;

    /**
     * 解锁库存
     *
     * @param order
     * @param detail
     * @param goods
     * @param nullableSku
     * @param request
     * @throws AppException
     */
    void refund(GoodsOrder order, GoodsOrderDetail detail, Goods goods, GoodsSku nullableSku, HttpServletRequest request) throws AppException;
}
